package com.zlcx.tz.live.web;

import com.zlcx.tz.live.client.UserClient;
import com.zlcx.tz.live.client.vo.LiveGatherVO;
import com.zlcx.tz.live.common.annotation.AutoLog;
import com.zlcx.tz.live.common.annotation.RepeatSubmit;
import com.zlcx.tz.live.constant.RedisKeyConst;
import com.zlcx.tz.live.domain.LiveFree;
import com.zlcx.tz.live.domain.LiveSwitched;
import com.zlcx.tz.live.exception.BusinessException;
import com.zlcx.tz.live.exception.CheckParamException;
import com.zlcx.tz.live.exception.CheckRunException;
import com.zlcx.tz.live.exception.VideoLimitException;
import com.zlcx.tz.live.service.impl.LiveRoomJoinRecordService;
import com.zlcx.tz.live.service.impl.LiveRoomService;
import com.zlcx.tz.live.service.impl.UserService;
import com.zlcx.tz.live.utils.ClientUtil;
import com.zlcx.tz.live.vo.*;
import com.zlcx.tz.live.vo.page.PageResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import static com.zlcx.tz.live.common.annotation.AutoLog.Level.DEBUG;
import static com.zlcx.tz.live.common.annotation.AutoLog.Level.INFO;
import static com.zlcx.tz.live.common.config.RedisConfig.CacheKeys.ROOM_FREE_NUM;
import static com.zlcx.tz.live.constant.ResultStatus.*;

/**
 * @AUTHOR xhl
 * @CREATE 2019-04-18 10:43
 **/
@RestController
@Slf4j
@Api(tags = {"直播房间管理"}, description = "直播房间管理相关接口")
@RequestMapping("/liveRoom")
public class LiveRoomManagerController extends BaseController {

    @Autowired
    LiveRoomService liveRoomService;

    @Autowired
    LiveRoomJoinRecordService liveRoomJoinRecordService;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    private UserClient userClient;

    private Logger traceLoger = LoggerFactory.getLogger("traceloger");

    @AutoLog
    @PreAuthorize("isAuthenticated()")
    @ApiOperation(value = "非VIP用户每天的免费次数和每次免费时长", notes = "非VIP用户每天的免费次数和每次免费时长")
    @GetMapping(value = "/free/{userId}")
    public ResultVO<LiveFree> applyPublish(@ApiParam(value = "用户id", required = true) @PathVariable Long userId) {
        LiveFree liveFree = liveRoomJoinRecordService.getLiveFree(1L);
        Object numObj = redisTemplate.opsForValue().get(ROOM_FREE_NUM + userId);
        if (Objects.nonNull(numObj)) {
            int useNum = Integer.parseInt(numObj.toString());
            liveFree.setFreeNum(liveFree.getTotalFreeNum() - useNum);
        } else {
            liveFree.setFreeNum(liveFree.getTotalFreeNum());
        }
        return successState(liveFree);

    }

    @AutoLog(logLevel = DEBUG)
    @GetMapping("/roomList")
    @ApiOperation(value = "查询直播列表", notes = "查询直播列表", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO getRoomList(@ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") Integer page,
                                @ApiParam(value = "条数") @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                @ApiParam(value = "用户id") @RequestParam(required = false) Long userId) {
        try {
            page--;
            PageResultVO resultVO = liveRoomService.findRoomList(userId, page, pageSize);
            return successState(resultVO);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("getRoomList failed reason", e);
            throw new CheckRunException("查询直播列表失败!", e);
        }
    }

    @AutoLog(logLevel = INFO)
    @GetMapping("/getHomePageList")
    @ApiOperation(value = "查询首页房间列表", notes = "查询首页房间列表", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO getHomePageList(@ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") Integer page,
                                    @ApiParam(value = "条数") @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                    @ApiParam(value = "用户id") @RequestParam(required = false) Long userId,
                                    @ApiParam(value = "创建时间") @RequestParam(required = false) String createTime) {
        try {
            page--;
            PageResultVO resultVO = liveRoomService.getHomePageList(userId, page, pageSize, createTime);
            return successState(resultVO);
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("getHomePageList failed reason", e);
            throw new CheckRunException("查询首页房间列表失败!", e);
        }
    }

    @AutoLog
    @RepeatSubmit
    @GetMapping("/quickJoinRoom")
    @ApiOperation(value = "快速加入房间", notes = "快速加入房间（如果token为空则默认为游客模式）")
    public ResultVO fastJoinRoom(@ApiParam(value = "token") @RequestHeader(required = false) String authorization) {

        try {
            Long currentUserId = currentUserId();
            Long resultVO = liveRoomService.quickJoinRoom(currentUserId);
            if (resultVO == 0L) {
                return new ResultVO(NO_EXISTS_ROOM.getCode(), NO_EXISTS_ROOM.getTips());
            }
            return successState(resultVO);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("quickJoinRoom failed reason", e);
            throw new CheckRunException("快速加入房间失败!", e);
        }
    }

    @AutoLog
    @PreAuthorize("isAuthenticated()")
    @RepeatSubmit
    @PostMapping("/createRoom")
    @ApiOperation(value = "创建房间", notes = "创建房间", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO createRoom(@ApiParam(value = "token", required = true) @RequestHeader String authorization,
                               @ApiParam(value = "房间信息") @RequestBody RoomInfoParamVO room) {

        traceLoger.info("【用户操作】 房主【{}】预创建房间【{}】", room.getOwnerUserId(), room.getRoomName());

        //TODO  1、开关 2、校验是否vip会员
        LiveSwitched switched = liveRoomJoinRecordService.getSwitched(1L);
        if (switched.getSwitched().intValue() == LiveSwitched.SwitchEnum.ON.code.intValue()) {
            //开关打开，然后禁止所有老版本app连麦
            throw new VideoLimitException("该版本已经停止连麦服务，请下载最新版本APP！");

        }
        RoomInfoVO resultVO = liveRoomService.insertRoomInfo(room);
        traceLoger.info("【用户操作】 房主【{}】房间【{}】预创建房间成功  【{}】 ", room.getOwnerUserId(), resultVO.getId(), room.getRoomName());
        return successState(resultVO);

    }

    @AutoLog
    @PreAuthorize("isAuthenticated()")
    @RepeatSubmit
    @PostMapping("/createRoom/v3")
    @ApiOperation(value = "3.0版本创建房间", notes = "3.0版本创建房间", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO createRoomV3(@ApiParam(value = "token", required = true) @RequestHeader String authorization,
                                 @ApiParam(value = "房间信息") @RequestBody RoomInfoParamVO room) {

        traceLoger.info("【用户操作】 房主【{}】预创建房间【{}】", room.getOwnerUserId(), room.getRoomName());

        //TODO  校验是否vip会员，前三天逻辑等
        try {
            //检查是否是vip用户
            LiveGatherVO gather = userClient.gather(room.getOwnerUserId()).getData();
            if (!gather.getIsAllow()) {
                return new ResultVO(VIP_USE_OVER_ERROR.getCode(), VIP_USE_OVER_ERROR.getTips());
            } else if (!gather.getIsCreateRoom()) {
                return new ResultVO(NO_VIP_CREATE_ROOM_ERROR.getCode(), NO_VIP_CREATE_ROOM_ERROR.getTips());
            } else if (Objects.nonNull(gather.getLiveExperience())) {
                Object numObj = redisTemplate.opsForValue().get(ROOM_FREE_NUM + room.getOwnerUserId());
                if (Objects.nonNull(numObj)) {
                    int useNum = Integer.parseInt(numObj.toString());
                    LiveFree liveFree = liveRoomJoinRecordService.getLiveFree(1L);
                    if (useNum >= liveFree.getTotalFreeNum()) {
                        return new ResultVO(LIVE_NUMS_USE_ERROR.getCode(), LIVE_NUMS_USE_ERROR.getTips());
                    }
                }
            }
            RoomInfoVO resultVO = liveRoomService.insertRoomInfo(room);
            traceLoger.info("【用户操作】 房主【{}】房间【{}】预创建房间成功  【{}】 ", room.getOwnerUserId(), resultVO.getId(), room.getRoomName());
            return successState(resultVO);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("createRoomV3 failed reason", e);
            throw new CheckRunException("创建房间失败!", e);
        }
    }

    @AutoLog
    @PreAuthorize("isAuthenticated()")
    @RepeatSubmit
    @PostMapping("/updateRoom/v3")
    @ApiOperation(value = "3.0版本修改房间信息", notes = "3.0版本修改房间信息", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO updateRoomV3(@ApiParam(value = "房间信息") @RequestBody RoomInfoParamVO room) {
        try {
            RoomInfoVO resultVO = liveRoomService.updateRoomInfo(room);
            traceLoger.info("【用户操作】 房主【{}】房间【{}】修改房间成功  【{}】 ", room.getOwnerUserId(), resultVO.getId(), room.getRoomName());
            return successState(resultVO);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("updateRoomV3 failed reason", e);
            throw new CheckRunException("修改房间失败!", e);
        }
    }

    @AutoLog
    @PreAuthorize("isAuthenticated()")
    @RepeatSubmit
    @PostMapping("/createRoomResultCallBack")
    @ApiOperation(value = "创建房间回调", notes = "创建房间回调", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO createRoomResultCallBack(@ApiParam(value = "token", required = true) @RequestHeader String authorization,
                                             @ApiParam(value = "房间信息") @RequestBody RoomInfoParamVO room,
                                             HttpServletRequest request) {

        traceLoger.info("【用户操作】 房主【{}】房间【{}】 创建房间回调", room.getOwnerUserId(), room.getId());
        try {
            String os = ClientUtil.getOs(request);
            if (!os.equals("IPhone")) {
                os = "Android";
            }
            RoomInfoVO resultVO = liveRoomService.createRoomCallBack(room, os);

            LiveGatherVO gather = userClient.gather(room.getOwnerUserId()).getData();
            if (Objects.nonNull(gather.getLiveExperience())) {
                //修改每天免费次数--redis
                LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
                long seconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
                Object numObj = redisTemplate.opsForValue().get(ROOM_FREE_NUM + room.getOwnerUserId());
                if (Objects.isNull(numObj)) {
                    redisTemplate.opsForValue().set(ROOM_FREE_NUM + room.getOwnerUserId(), 1, seconds, TimeUnit.SECONDS);
                } else {
                    redisTemplate.opsForValue().increment(ROOM_FREE_NUM + room.getOwnerUserId(), 1);
                }
            }

            return successState(resultVO);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("createRoomResultCallBack failed reason", e);
            throw new CheckRunException("创建房间回调失败!", e);
        }
    }

    @AutoLog(logLevel = DEBUG)
    @GetMapping("/roomInfo/{roomId}")
    @ApiOperation(value = "查询房间信息", notes = "查询房间信息（如果token为空则默认为游客模式）", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO roomInfo(@ApiParam(value = "token") @RequestHeader(required = false) String authorization,
                             @ApiParam(value = "房间id", required = true) @PathVariable Long roomId,
                             @ApiParam(value = "用户id（不传默认为观众身份）") @RequestParam(required = false) Long userId,
                             HttpServletRequest request) {
        String os = ClientUtil.getOs(request);
        if (!os.equals("IPhone")) {
            os = "Android";
        }
        RoomInfoVO resultVO = liveRoomService.roomInfoVO(roomId, userId, StringUtils.isBlank(authorization), os);
        return successState(resultVO);

    }

    @AutoLog(logLevel = DEBUG)
    @GetMapping("/roomInfoSimple/{roomId}")
    @ApiOperation(value = "查询简版房间信息", notes = "查询简版房间信息", response = RoomInfoSimpleVO.class, responseContainer = "Map")
    public ResultVO roomInfoSimple(@ApiParam(value = "房间id", required = true) @PathVariable Long roomId) {
        try {
            RoomInfoSimpleVO resultVO = liveRoomService.roomInfoSimple(roomId);
            return successState(resultVO);
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("roomInfoSimple failed reason", e);
            throw new CheckRunException("查询简版房间信息失败!", e);
        }
    }

    @AutoLog
    @PreAuthorize("isAuthenticated()")
    @RepeatSubmit
    @PostMapping("/closeRoom")
    @ApiOperation(value = "关闭房间", notes = "关闭房间", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO closeRoom(@ApiParam(value = "token", required = true) @RequestHeader String authorization,
                              @ApiParam(value = "房间信息") @RequestBody UserJoinVO userJoinVO) {

        traceLoger.info("【用户操作】 房主【{}】关闭房间【{}】 ", userJoinVO.getUserId(), userJoinVO.getRoomId());

        try {
            if (userJoinVO.getUserId() == null) {
                throw new CheckParamException("userId不能为空");
            }
            if (userJoinVO.getRoomId() == null) {
                throw new CheckParamException("roomId不能为空");
            }
            liveRoomService.roomOwnerClosedRoom(userJoinVO.getUserId(), userJoinVO.getRoomId());
            return successState();
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("closeRoom failed reason ", e);
            throw new CheckRunException("关闭房间失败!", e);
        }
    }

    @AutoLog
    @RepeatSubmit
    @PostMapping("/joinRoom")
    @ApiOperation(value = "加入房间", notes = "加入房间（如果token为空则默认为游客模式）", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO joinRoom(@ApiParam(value = "token") @RequestHeader(required = false) String authorization,
                             @ApiParam(value = "version") @RequestHeader(required = false) String version,
                             @ApiParam(value = "加入房间数据") @RequestBody UserJoinVO userJoinVO,
                             HttpServletRequest request) {
        String os = ClientUtil.getOs(request);
        if (!os.equals("IPhone")) {
            os = "Android";
        }
        traceLoger.info("【用户操作】 用户【{}】加入房间【{}】 ", userJoinVO.getUserId(), userJoinVO.getRoomId());
        try {
            if (userJoinVO.getUserId() == null) {
                throw new CheckParamException("userId不能为空");
            }
            if (userJoinVO.getRoomId() == null) {
                throw new CheckParamException("roomId不能为空");
            }
            boolean sendMsg = true;
            boolean checkAudienceJoin = false;
//            if (StringUtils.isNotBlank(version) && compareVersion(version, "2.4") == 1) {
//                sendMsg = true;
//                checkAudienceJoin = false;
//            }
            RoomInfoVO resultVO = liveRoomService.joinRoom(userJoinVO.getUserId(), userJoinVO.getRoomId(), StringUtils.isBlank(authorization), sendMsg, checkAudienceJoin, os);
            return successState(resultVO);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("joinRoom failed reason", e);
            throw new CheckRunException("加入房间失败!", e);
        }
    }

    @AutoLog
    @RepeatSubmit
    @PostMapping("/exitRoom")
    @ApiOperation(value = "退出房间", notes = "退出房间（如果token为空则默认为游客模式）", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO exitRoom(@ApiParam(value = "token") @RequestHeader(required = false) String authorization,
                             @ApiParam(value = "version") @RequestHeader(required = false) String version,
                             @ApiParam(value = "退出房间数据") @RequestBody UserJoinVO userJoinVO) {

        traceLoger.info("【用户操作】 用户【{}】退出房间【{}】 ", userJoinVO.getUserId(), userJoinVO.getRoomId());
        try {
            if (userJoinVO == null) {
                throw new CheckParamException("参数不能为空");
            }
            if (userJoinVO.getUserId() == null) {
                throw new CheckParamException("userId不能为空");
            }
            if (userJoinVO.getRoomId() == null) {
                throw new CheckParamException("roomId不能为空");
            }
            boolean sendMsg = true;
//            if (StringUtils.isNotBlank(version) && compareVersion(version, "2.4") == 1) {
//                sendMsg = true;
//            }
            liveRoomService.exitRoom(userJoinVO.getUserId(), userJoinVO.getRoomId(), StringUtils.isBlank(authorization), sendMsg);
            return successState();
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("exitRoom failed reason", e);
            throw new CheckRunException("退出房间失败!", e);
        }
    }

    @AutoLog
    @PreAuthorize("isAuthenticated()")
    @RepeatSubmit
    @GetMapping("/kickingUser")
    @ApiOperation(value = "踢出房间", notes = "踢出房间", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO kickingUser(@ApiParam(value = "token", required = true) @RequestHeader String authorization,
                                @ApiParam(value = "房主id") @RequestParam Long ownerUserId,
                                @ApiParam(value = "踢出目标id") @RequestParam Long targetUserId,
                                @ApiParam(value = "房间id") @RequestParam Long roomId) {

        traceLoger.info("【用户操作】房主【{}】将用户【{}】踢出房间【{}】 ", ownerUserId, targetUserId, roomId);
        try {
            liveRoomService.kickingUser(ownerUserId, targetUserId, roomId);
            return successState();
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("kickingUser failed reason", e);
            throw new CheckRunException("踢出房间失败!", e);
        }
    }

    @AutoLog(logLevel = DEBUG)
    @GetMapping("/getUserIdsByRoomId")
    @ApiOperation(value = "根据房间id查询用户id", notes = "根据房间id查询用户id", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO getUserIdsByRoomId(@ApiParam(value = "查询类型 1-连麦用户，2-观众，其他-全部用户") @RequestParam(defaultValue = "0") Integer queryType,
                                       @ApiParam(value = "房间id") @RequestParam Long roomId) {
        try {
            if (roomId == null) {
                throw new CheckParamException("roomId不能为空");
            }
            List<Long> resultVO = liveRoomService.getUserIdsByRoomId(roomId, queryType);
            return successState(resultVO);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("getUserIdsByRoomId failed reason", e);
            throw new CheckRunException("根据房间id查询用户id失败!", e);
        }
    }

    @AutoLog
    @RepeatSubmit
    @ApiOperation(value = "管理员关闭房间", notes = "管理员关闭房间")
    @GetMapping(value = "/adminCloseRoom/{roomId}/{sign}")
    public ResponseEntity<ResultVO> adminCloseRoom(
            @ApiParam(value = "房间id", required = true) @PathVariable Long roomId,
            @ApiParam(value = "密钥", required = true) @PathVariable String sign) {

        try {
            if (roomId == null) {
                throw new CheckParamException("roomId不能为空");
            }

            String adminCloseRoomSignKey = RedisKeyConst.getAdminCloseRoomSignKey(roomId);
            String oldSign = (String) redisTemplate.opsForValue().get(adminCloseRoomSignKey);
            if (StringUtils.isBlank(oldSign) || !oldSign.equals(sign)) {
                throw new BusinessException("非法操作！");
            }

            liveRoomService.administratorCloseRoom(roomId);
            return ResponseEntity.ok(successState());

        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("管理员关闭房间，roomId={},sign={}", roomId, sign, e);
            throw new CheckRunException("管理员关闭房间失败!", e);
        }

    }

    @AutoLog
    @RepeatSubmit
    @ApiOperation(value = "管理员踢人", notes = "管理员踢人")
    @GetMapping(value = "/adminKickingUser/{userId}")
    public ResponseEntity<ResultVO> adminKickingUser(
            @ApiParam(value = "用户id", required = true) @PathVariable Long userId,
            @ApiParam(value = "密钥", required = true) @RequestParam String sign) {

        try {
            if (userId == null) {
                throw new CheckParamException("userId不能为空");
            }

            boolean signOk = false;
            if (sign == null) {
                signOk = false;
            } else if (getSign().equals(sign)) {
                signOk = true;
            } else {

                String signKey = RedisKeyConst.getAdminKickingUserSignKey(userId);
                String oldSign = (String) redisTemplate.opsForValue().get(signKey);
                if (StringUtils.isNotBlank(oldSign) && oldSign.equals(sign)) {
                    signOk = true;
                }
            }

            if (!signOk) {
                throw new CheckParamException("非法操作");
            }

            liveRoomService.adminKickingUser(userId, "admin");

            return ResponseEntity.ok(successState());

        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("管理员踢人，userId={},sign={}", userId, sign, e);
            throw new CheckRunException("管理员踢人失败!", e);
        }

    }

    @AutoLog(logLevel = DEBUG)
    @GetMapping("/getPublisherInfo/{userId}")
    @ApiOperation(value = "查询用户当前连麦信息--服务端调用", notes = "查询用户当前连麦信息--服务端调用", response = RoomInfoVO.class, responseContainer = "Map")
    public ResultVO<RoomPublisherVO> getPublisherInfoByUserId(@ApiParam(value = "用户id", required = true) @PathVariable Long userId) {
        try {
            RoomPublisherVO record = liveRoomService.findPublisherRecordByUserId(userId);
            return successState(record);
        } catch (CheckParamException e) {
            throw e;
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("getUserIdsByRoomId failed reason", e);
            throw new CheckRunException("查询用户当前连麦信息--服务端调用失败!", e);
        }
    }

    @AutoLog
    @RepeatSubmit
    @ApiOperation(value = "管理员关闭房间", notes = "管理员关闭房间")
    @PutMapping(value = "/avatar")
    public ResponseEntity<ResultVO> changeRoomAvatar(
            @ApiParam(value = "用户id", required = true) @RequestParam Long userId,
            @ApiParam(value = "房间id", required = true) @RequestParam Long roomId,
            @ApiParam(value = "房间头像", required = true) @RequestParam String avatar) {

        boolean isOwner = liveRoomJoinRecordService.verifyOwner(roomId, userId);
        if (isOwner) {
            liveRoomService.updateRoomAvatar(roomId, avatar);
        }
        return null;
    }

    @AutoLog
    @ApiOperation(value = "查询所有开着的房间ids", notes = "查询所有开着的房间ids")
    @GetMapping(value = "/list/roomIds")
    public ResultVO listRoomIds() {
        List<Long> roomIds = liveRoomService.findAllOpenRoomIds();
        return successState(roomIds);
    }

    private String getSign() {
        return org.apache.commons.lang3.StringUtils.reverse(DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.format(new Date()));
    }


}
